class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param tokens string字符串vector
     * @return int整型
     */
    int char2int(string s){
        int op = 1;
        int i = 0;
        if (s[0] == '-') {
            op = -1;
            i = 1;
        }
        int sum = 0;
        for(; i < s.length(); i++){
            sum = sum * 10 + s[i] - '0';
        }
        return sum * op;
    }
    int evalRPN(vector<string>& tokens) {
        // write code here
        stack<int> st;
        int tmp1, tmp2, tmp;
        for(auto it : tokens){
            if (it == "+" || it == "-" || it == "*" || it == "/"){
                tmp2 = st.top();
                st.pop();
                tmp1 = st.top();
                st.pop();
                if (it == "+"){
                    tmp = tmp1 + tmp2;
                    st.push(tmp);
                }
                if (it == "-"){
                    tmp = tmp1 - tmp2;
                    st.push(tmp);
                }
                if (it == "*"){
                    tmp = tmp1 * tmp2;
                    st.push(tmp);
                }
                if (it == "/"){
                    tmp = tmp1/tmp2;
                    st.push(tmp);
                }
            } else {
                st.push(char2int(it));
            }
        }
        tmp = st.top();
        st.pop();
        return tmp;
    }
};